import request from '/@/utils/request';

export const pageList = (data?: Object) => {
	return request({
		url: '/admin/V1/menu/tree',
		method: 'post',
		data: data,
	});
};
export const menuTreeRoleId = (data?: Object) => {
	return request({
		url: '/admin/V1/menu/tree/roleId',
		method: 'post',
		data: data,
	});
};
export const info = (id: String) => {
	return request({
		url: `/admin/V1/menu/id`,
		method: 'post',
		data: { id: id },
	});
};

export const save = (data: Object) => {
	return request({
		url: '/admin/V1/menu',
		method: 'post',
		data: data,
	});
};

export const putObj = (data: Object) => {
	return request({
		url: '/admin/V1/menu/update',
		method: 'post',
		data: data,
	});
};

export const addObj = (data: Object) => {
	return request({
		url: '/admin/V1/menu/add',
		method: 'post',
		data: data,
	});
};

export const delObj = (data: object) => {
	return request({
		url: '/admin/V1/menu/deleted',
		method: 'post',
		data: data,
	});
};

/**
 * 后端控制路由，isRequestRoutes 为 true，则开启后端控制路由
 * @method getAdminMenu 获取后端动态路由菜单(admin)
 */
export function useMenuApi() {
	return {
		getAdminMenu: (data?: object) => {
			return request({
				url: '/admin/V1/menu',
				method: 'post',
				data: data,
			});
		},
	};
}
